package com.kehan.order.common.creatorBean;

import com.kehan.order.common.interfaces.Generator;
import com.kehan.order.modular.order.Coffer;
import com.kehan.order.modular.order.Tea;

import java.util.Iterator;
import java.util.Random;

public class CofferGenerator implements Generator<Coffer> , Iterable<Coffer> {


    private Class[] types = {Tea.class};

    private static Random random = new Random(47);

    public CofferGenerator() {

    }

    private int size=0;

    public CofferGenerator(int rz) {
        this.size = rz;
    }


    @Override
    public Coffer next() {
        try {
            return (Coffer) types[random.nextInt(types.length)].newInstance();
        }catch (Exception e){
            throw new RuntimeException();
        }
    }




    public Iterator<Coffer> iterator(){
        return new CofferIterator();
    }



    class CofferIterator implements Iterator<Coffer>{

        int count = size;

        @Override
        public boolean hasNext() {
            return count>0;
        }

        @Override
        public Coffer next() {
            count--;
            return CofferGenerator.this.next();
        }
    }


    public static void main(String[] args) {

       for(Coffer c : new CofferGenerator(5)){
            System.out.println(c);
        }
    }
    
}
